package com.imooc.sell.vo;

import lombok.Data;

@Data
public class ResultVO<T> {

    public static final int SUCCESS_CODE = 0;

    public static final String SUCCESS_MSG = "成功";


    /**
     * code
     */
    private Integer code;

    /**
     * msg
     */
    private String msg;


    private T data;

    public ResultVO() {
    }

    public ResultVO(Integer code, String msg) {
        this(code, msg, null);
    }

    public ResultVO(Integer code, String msg, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public static ResultVO success() {
        return success(null);
    }

    public static <T> ResultVO success(T data) {
        return new ResultVO(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static ResultVO error(Integer code,String msg){
        return error(code,msg,null);
    }

    public static ResultVO commonError(){
        return error(9999,"失败");
    }

    public static <T> ResultVO error(Integer code,String msg,T data){
        return new ResultVO(code,msg,data);
    }


}
